package com.junlaninfo;

import java.util.ArrayList;
import java.util.List;

/**
  使用ArrayList做hashmap
 **/
public class ArrayListHashMap<K, V> {
    private List<Entry<K, V>> entrys = new ArrayList<Entry<K, V>>();

    //      entry对象 键值对对象
    class Entry<K, V> {
        K k;
        V v;

        public Entry(K k, V v) {
            this.k = k;
            this.v = v;
        }
    }

    public void put(K k, V v) {
        entrys.add(new Entry<K, V>(k, v));
    }

    public V get(K k) {
        for (Entry<K, V> entry : entrys) {
            if (entry.k != null && entry.k.equals(k)) {
                return entry.v;
            }
        }
        return null
                ;
    }

    public static void main(String[] args) {
        ArrayListHashMap<Object, Object> hashMap = new ArrayListHashMap<Object, Object>();
        hashMap.put("name","xuexionghui");
        System.out.println(hashMap.get("name"));
    }
}
